package com.gbits.app.finance.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import com.gbits.app.finance.domain.SubjectBusinessMapper;
import com.gbits.app.finance.service.DefaultAbstractService;
import com.gbits.app.finance.service.SubjectBusinessMapperService;

@Service("subjectBusinessMapperService")
@Transactional
public class SubjectBusinessMapperServiceImpl extends DefaultAbstractService<SubjectBusinessMapper>
		implements SubjectBusinessMapperService {

	public SubjectBusinessMapper getBusinessMapper(String orgCode,
			String subjectName) {
		
		Assert.notNull(orgCode, "机构代码不能为空");
		Assert.notNull(subjectName, "科目名称不能为空");
		
		String hql = "from " + SubjectBusinessMapper.class.getName() + " e where e.orgCode=:orgCode and e.lastSubjectName =:name";
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("orgCode", orgCode);
		map.put("name", subjectName);
		List<SubjectBusinessMapper> list = this.getBaseDao().findByNamesParameter(hql, map);
		if (null == list || list.isEmpty()) {
			throw new RuntimeException("未找到匹配的业务类型[" + subjectName + "]");
		}
		
		if (list.size() > 1) {
			throw new RuntimeException("找到匹配的业务类型[" + subjectName + "]重复");
		}
		
		
		return list.get(0);
	}

}
